package net.siufung.security.provider;

import com.google.common.collect.Lists;
import lombok.Getter;
import net.siufung.security.provider.dto.PasswdLoginDto;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 密码授权Token
 * @author 陈建峰
 * @since 2022/3/3 4:51 下午
 */
public class PasswdAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 8783850966923998803L;
    /**
     * 用户主体
     */
    private Object principal;
    /**
     * 认证证书
     */
    private String credential;
    /**
     * 令牌登录对象
     */
    @Getter
    private PasswdLoginDto passwdLoginDto;

    public PasswdAuthenticationToken(PasswdLoginDto passwdLoginDto) {
        super(Lists.newArrayList());
        this.passwdLoginDto = passwdLoginDto;
    }

    public PasswdAuthenticationToken(Object principal, String credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credential = credentials;
        setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return this.credential;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
